using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AttackForward : KoishiEffect
{
    public Attack attack;
    public ButtonInput buttonInput;

    void Start()
    {
        attack = owner.gameObject.GetComponent<Attack>();
        buttonInput = owner.gameObject.GetComponent<ButtonInput>();
    }

    void Update()
    {
        MoveWithOwner();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.gameObject.CompareTag("enemy"))
        {
            Rebound();
            attack.HarmEnemy(collision);
        }

        if (collision.gameObject.CompareTag("sharpGround"))
        {
            Rebound();
        }

        if (collision.gameObject.CompareTag("ground"))
        {
            Rebound();
        }
    }
    private void Rebound()
    {
        if (buttonInput.canControl) owner.speed.x = owner.speed.x * 0.5f  - owner.direction * 1;
    }
}
